package org;

import user.User;

public class PWCrypt {

	public static String scramblePW(User user) {
		String pw=user.getPassword();
		char[] ch=new char[pw.length()];
		for(int i=0;i<ch.length;i++) {
			short x=(short)pw.charAt(i);
			x=(short)( (x + 3*(pw.length())) - (5+user.getId())*user.getName().length() - (pw.length()-i) );
			ch[i]=(char)x;
		}
		return new String(ch);
	}
	public static String unscramblePW(String pw,String username,int id) {
		char[] ch=new char[pw.length()];
		for(int i=0;i<ch.length;i++) {
			short x=(short)pw.charAt(i);
			x=(short)(( x + (5+id)*username.length()) - 3*(pw.length()) + (pw.length()-i));
			ch[i]=(char)x;
		}
		return new String(ch);
	}
	
	
	//uninstantiable class with only static methods
	private PWCrypt() {
	}
}
